// pages/my/muchdetail.js
import service from '../../services/money.js';
import util from '../../utils/util.js';



Page({

  /**
   * 页面的初始数据
   */
  data: {
    balance: '0.00',
    pages: 0,
    per_page: 20,
    list: [],
    endBloon: false,
    loadflag: true
  },

  getmoneydetail(page) {
    let that = this;
    let param = {
      page: page,
      offset: that.data.per_page
    }
    service.getbilllist(param, function (res) {
      if (res && res.code == 1) {
        that.setData({
          pages: page + 1,
          endBloon: true,
        })
        let list = res.data;
        let dataCount = res.count;
        for (let i in list) {
          if (list[i].bill_type == 1) {
            list[i].bill_type_str = '+';
            list[i].bill_type_col = 'coljia';
          } else if (list[i].bill_type == 2) {
            list[i].bill_type_str = '-';
            list[i].bill_type_col = 'coljian';
          }
          if (list[i].bill_money != null && list[i].bill_money != '' && !isNaN(Number(list[i].bill_money))) {
            list[i].bill_money = util.toDecimal2(util.floatAccMul(list[i].bill_money, 1));
          }
          if (list[i].bill_balance != null && list[i].bill_balance != '' && !isNaN(Number(list[i].bill_balance))) {
            list[i].bill_balance = util.toDecimal2(util.floatAccMul(list[i].bill_balance, 1));
          }
        }
        list = that.data.list.concat(list);
        that.setData({
          list: list,
          
        });
        if (dataCount == list.length) {
          that.setData({
            loadflag: false
          })
        }
      } else {
        // wx.showToast({
        //   title: res.msg,
        //   icon: 'none'
        // })
      }
    })
  },
  //获取用户余额
  getCustomerBalance() {
    let that = this;
    service.getcustomerbalance({}, function (res) {
      if (res && res.code == 1) {
        that.setData({
          balance: res.balance,
          count_balance: res.count
        })
      }
    })
  },






  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getmoneydetail(1);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getCustomerBalance()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this;
    //页面初始加载数据
    if (that.data.loadflag && that.data.endBloon) {
      that.setData({
        endBloon: false
      })
      that.getmoneydetail(that.data.pages);
    }
  },
})